<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .btn {
            display: inline-block;
            width: 50px;
            height: 30px;
            border: 1px solid black;
            line-height: 30px;
            margin: 50px 20px;
            text-align: center;
        }

        .wrap {
            width: 1220px;
            height: 100px;
            border: 1px black solid;
            position: relative;
            margin: 20px auto;
        }

        .box {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background: aqua;
            position: absolute;
            left: 0;
        }
    </style>
</head>

<body>
    <span class="btn">开始</span><span class="btn">暂停</span><span class="btn">复位</span>
    <div class="wrap">
        <div class="box"></div>
    </div>
</body>
<script>

    var start = document.getElementsByClassName('btn')[0]
    var _stop = document.getElementsByClassName('btn')[1]
    var again = document.getElementsByClassName('btn')[2]
    var wrap = document.getElementsByClassName('wrap')[0]
    var box = document.getElementsByClassName('box')[0]
    var max = wrap.clientWidth - box.clientWidth
    var dong = 0, timer = null

    start.onclick = function () {
        clearInterval(timer)
        if (dong >= max) { return }
        timer = setInterval(() => {
            dong += 20
            box.style.left = dong + 'px'
            if (dong >= max) {
                clearInterval(timer)
            }
        }, 20)
    }
    _stop.onclick = function () {
        clearInterval(timer)
    }
    again.onclick = function () {
        clearInterval(timer)
        if (dong <= 0) { return }
        timer = setInterval(() => {
            dong -= 20
            box.style.left = dong + 'px'
            if (dong <= 0) {
                clearInterval(timer)
            }
        }, 10)
    }










</script>

</html>